package com.ruoyi.audit.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.domain.UserCashRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.PreAuthorize;
import com.ruoyi.audit.service.IUserCashRecordService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 用户提现记录Controller
 * 
 * @author ruoyi
 * @date 2021-03-24
 */
@RestController
@RequestMapping("/user")
public class UserCashRecordController extends BaseController
{
    @Autowired
    private IUserCashRecordService userCashRecordService;

    /**
     * 查询用户提现记录列表
     */
    @PreAuthorize(hasPermi = "audit:user:list")
    @GetMapping("/list")
    public TableDataInfo list(UserCashRecord userCashRecord)
    {
        startPage();
        List<UserCashRecord> list = userCashRecordService.selectUserCashRecordList(userCashRecord);
        return getDataTable(list);
    }

    /**
     * 导出用户提现记录列表
     */
    @PreAuthorize(hasPermi = "audit:user:export")
    @Log(title = "用户提现记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, UserCashRecord userCashRecord) throws IOException
    {
        List<UserCashRecord> list = userCashRecordService.selectUserCashRecordList(userCashRecord);
        ExcelUtil<UserCashRecord> util = new ExcelUtil<UserCashRecord>(UserCashRecord.class);
        util.exportExcel(response, list, "user");
    }

    /**
     * 获取用户提现记录详细信息
     */
    @PreAuthorize(hasPermi = "audit:user:query")
    @GetMapping(value = "/{cashid}")
    public AjaxResult getInfo(@PathVariable("cashid") Long cashid)
    {
        return AjaxResult.success(userCashRecordService.selectUserCashRecordById(cashid));
    }

    /**
     * 新增用户提现记录
     */
    @PreAuthorize(hasPermi = "audit:user:add")
    @Log(title = "用户提现记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UserCashRecord userCashRecord)
    {
        return toAjax(userCashRecordService.insertUserCashRecord(userCashRecord));
    }

    /**
     * 修改用户提现记录
     */
    @PreAuthorize(hasPermi = "audit:user:edit")
    @Log(title = "用户提现记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UserCashRecord userCashRecord)
    {
        return toAjax(userCashRecordService.updateUserCashRecord(userCashRecord));
    }

    /**
     * 删除用户提现记录
     */
    @PreAuthorize(hasPermi = "audit:user:remove")
    @Log(title = "用户提现记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{cashids}")
    public AjaxResult remove(@PathVariable Long[] cashids)
    {
        return toAjax(userCashRecordService.deleteUserCashRecordByIds(cashids));
    }
}
